<?php

class Application_Form_Registration extends Zend_Form
{
	
        public function __construct()
	{
            $translate = new My_Action_Helper_Lang();
            
            $this->setName('form_registration');
            parent::__construct();

            $login = new Zend_Form_Element_Text('email');
            $login->setLabel($translate->_('Email'))
                    ->setRequired(true)
                    ->addValidator('NotEmpty')
                    ->addValidator('Db_NoRecordExists', false, array(
                        'table' => 'users',
                        'field' => 'email'))
                    ->addValidator('EmailAddress')
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $password = new Zend_Form_Element_Password('password');
            $password->setLabel($translate->_('Password'))
                    ->setRequired(true)
                    ->addValidator('NotEmpty')
                    ->addValidator('StringLength', true, array(8,20))
                    ->addValidator('Alnum')
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $password_confirm = new Zend_Form_Element_Password('password_confirm');
            $password_confirm->setLabel($translate->_('Enter password again'))
                    ->setRequired(true)
                    ->addValidator('NotEmpty')
                    ->addValidator('Alnum')
                    //Указываем префикс, путь и тип созданого валидатора
                    ->addPrefixPath('myClass_Validator', 'myClass/Validator', 'validate')
                    ->addValidator('Passwordconfirm')
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $firstName = new Zend_Form_Element_Text('firstName');
            $firstName->setLabel($translate->_('Firstname'))
                    ->setRequired(true)
                    ->addValidator('NotEmpty')
                    ->addValidator('Alpha', false, array('allowWhiteSpace' => true))
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $lastName = new Zend_Form_Element_Text('lastName');
            $lastName->setLabel($translate->_('Lastname'))
                    ->setRequired(true)
                    ->addValidator('NotEmpty')
                    ->addValidator('Alpha', false, array('allowWhiteSpace' => true))
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $phone = new Zend_Form_Element_Text('phone');
            $phone->setLabel($translate->_('Phone'))
                    ->addValidator('Digits')
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $company = new Zend_Form_Element_Text('company');
            $company->setLabel($translate->_('Company'))
                    ->setRequired(true)
                    ->addValidator('NotEmpty')
                    ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            //создаем объект формы регистрация и модели
            $country = new Zend_Form_Element_Select('country');
            $table = new Application_Model_Registration();
            //добавляем опции в форму
            $country->addMultiOption(0, $translate->_('Please select country'));
            $country->setLabel($translate->_('Country'));
            //массивом передаем значения в select
            foreach ($table->getAllCountries() as $table) {
                $country->addMultiOption($table['id'], $table['name']);
            }


            $city = new Zend_Form_Element_Text('city');
            $city->setLabel($translate->_('City'))
                    ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $adress = new Zend_Form_Element_Text('adress');
            $adress->setLabel($translate->_('Address'))
                    ->addValidator('Alnum', false, array('allowWhiteSpace' => true))
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $site = new Zend_Form_Element_Text('site');
            $site->setLabel($translate->_('Site company'))
                    ->addFilter('StringTrim')
                    ->addFilter('StripTags');

            $submit = new Zend_Form_Element_Submit('submit');
            $submit->setLabel($translate->_('Registration'))
                   ->setAttrib('class', 'button');

            $this->addElements(array($login, $password, $password_confirm, 
                $firstName, $lastName, $phone, $company, $country, $city, $adress, $site, $submit));
	}
}